<?php
class CategoryAction extends BaseAction {
	
		public function index() {
				$zone = $_GET['zone'];
				$sub_zone = $_GET['sub_zone'];
				
				$listcate = D('Category')->selectByZone($zone,$sub_zone);
				$this->assign('listcate', $listcate);
				$this->display();
		}
	
	public function addCategory() {
		$this->assign('pid', intval($_GET['pid']));
		$this->display('edit');
	}
	
	public function editCategory() {
		$category = M('Category')->where('id='.$_GET['id'])->find();
		$this->assign('category', $category);
		$this->display('edit');
	}
	
	public function doAddCategory() {
		$map['name'] = $_POST['name'];
		$map['sub_zone'] = $_POST['sub_zone'];
		$map['sort_order'] = $_POST['sort_order'];
		$map['display'] = $_POST['display'];
		$map['zone'] = $_POST['zone'];
		$category = D('Category');
		echo ($res = $category->add($map)) ? $res : '0';
	}
	
	public function doEditCategory() {
		$map['name'] = $_POST['name'];
		$map['id'] = $_POST['id'];
		$map['sub_zone'] = $_POST['sub_zone'];
		$map['sort_order'] = $_POST['sort_order'];
		$map['display'] = $_POST['display'];
		$map['zone'] = $_POST['zone'];
		
		$category = D('Category');
		echo ($res = $category->save($map)) ? $res : '0';
	}
	
	public function doDeleteCategory() {
		$_POST['ids']	= explode(',', t($_POST['ids']));
		if (empty($_POST['ids'])) {
			echo 0;
			return ;
		}
		$map['id']	= array('in', $_POST['ids']);
		echo D('Category')->where($map)->delete() ? '1' : '0';
	}
	
}
?>